import { Controller, Post, Body, UseGuards, Req } from '@nestjs/common';
import { VoteService } from './vote.service';
import { VoteDto } from './dto/vote.dto';
import { AuthGuard } from '../../@nt/guards/auth.guard';
import { RestController } from '../../@nt';

// 投票控制器
@Controller('vote')
@UseGuards(AuthGuard)
export class VoteController extends RestController {
  constructor(protected readonly service: VoteService) {
    super(service);
  }

  // 提交投票
  @Post()
  async submitVote(@Body() body: VoteDto, @Req() req: Request): Promise<any> {
    const user = req['user'];
    const data: any = {
      userId: user.id,
      candidateId: body.candidateId,
    };
    return await this.service.submitVote(data);
  }
}
